﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Products;

public partial class admin_order_order : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String[] admin = Session["Admin"].ToString().Split(',');
        if (int.Parse(admin[0]) < 0)
        {
            Response.Redirect("http://localhost:2011/didong/admin/login.aspx");
        }
        if (!Page.IsPostBack)
        {
            Databind(2);
        }
    }
    protected void Databind(int Isactive)
    {
        this.Lproducts.DataSource = Orders.GetOrderByIsactive(Isactive);
        Lproducts.DataBind();
    }
    protected void Lproducts_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        ListViewItem item = Lproducts.Items[e.ItemIndex];
        if (item != null)
        {
            String Item = ((HiddenField)item.FindControl("hdid")).Value.ToString();
            bool result;
            result = Orders.Delete_Order(Convert.ToInt16(Item));
            if (result == false)
            {
                this.Lbmessage.Text = "Xoá không thành công";
            }
            else
            {
                this.Lbmessage.Text = "Xoá thành công";
                Databind(int.Parse(dropchon.SelectedValue.ToString()));

            }

        }
    }
    protected void Lproducts_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
        ListViewItem item = Lproducts.Items[e.ItemIndex];
        if (item != null)
        {
            String Item = ((HiddenField)item.FindControl("hdid")).Value.ToString();
            bool result;
            result = Orders.Update_UpdateActive(Convert.ToInt16(Item));
            if (result == false)
            {
                this.Lbmessage.Text = "cập nhật không thành công";
                Lbmessage.Visible = true;
            }
            else
            {
                this.Lbmessage.Text = "cập nhật  thành công";
                Databind(int.Parse(dropchon.SelectedValue.ToString()));

            }


        }
    }
    protected void dropchon_SelectedIndexChanged(object sender, EventArgs e)
    {
        Databind(int.Parse(dropchon.SelectedValue.ToString()));
    }
}
